package cn.tinlan.shopcoin.app.discover.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.tinlan.shopcoin.R;
import cn.tinlan.shopcoin.app.discover.model.DiscoverItemDataModel;
import cn.tinlan.shopcoin.widget.category.Constants;

/**
 * Created by Mortimer on 2018/11/23. 19:23
 * 佛祖🙏，永无bug。
 */
public class ScrollRightAdapter extends BaseSectionQuickAdapter<DiscoverItemDataModel, BaseViewHolder> {
    private Context mContext;
    public ScrollRightAdapter(Context context,int layoutResId, int sectionHeadResId, List<DiscoverItemDataModel> data) {
        super(layoutResId, sectionHeadResId, data);
        mContext = context;
    }

    @Override
    protected void convertHead(BaseViewHolder helper, DiscoverItemDataModel item) {
        helper.setText(R.id.right_title, item.header);

    }

    @Override
    protected void convert(final BaseViewHolder helper, DiscoverItemDataModel item) {
       final DiscoverItemDataModel.ScrollItemBean t = item.t;

        helper.setText(R.id.right_text, t.getName());

        ImageView img = helper.getView(R.id.right_img);
        Glide.with(mContext).load(Constants.IMGURL+t.getThumb()).into(img);

        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onRightItemClickListener != null) {
                    onRightItemClickListener.OnRightItemClickListener(t.getId(),t.getName(),helper.getAdapterPosition());
                }
            }
        });
    }

   public interface OnRightItemClickListener {
        public void OnRightItemClickListener(String id, String title,int position);
    }

    private OnRightItemClickListener onRightItemClickListener;

    public void setOnRightItemClickListener(OnRightItemClickListener onRightItemClickListener) {
        this.onRightItemClickListener = onRightItemClickListener;
    }
}
